from typing import List


class Solution:
    def waysToMakeFair(self, nums: List[int]) -> int:
        result = 0
        pre_odd = 0
        pre_even = 0
        end_even = sum([n for n in nums[::2]])
        end_odd = sum([n for n in nums[1::2]])

        is_even = True

        for n in nums:
            if is_even:
                end_even -= n
                if pre_even+end_odd == pre_odd+end_even:
                    result += 1
                pre_even += n
            else:
                end_odd -= n
                if pre_even+end_odd == pre_odd+end_even:
                    result += 1
                pre_odd += n
            is_even = not is_even

        return result


print(Solution().waysToMakeFair([6,1,7,4,1]))
